//declare sockaddr socket connect
#include <sys/types.h>
#include <sys/socket.h>


//declare htons inet_addr
#include <arpa/inet.h>

//declare sockaddr_in
#include <linux/in.h>

#define SERVER_PORT 8888
#define SERVER_IP "127.0.0.1" 
#define MAXBUF 1024
#define STDOUT 1
#define STDIN 0

#ifndef NULL
#define NULL ((void*)0)
#endif


typedef struct sockaddr SockAddr;
typedef struct sockaddr_in SockAddrIn;

static SockAddrIn s_addr_in;
static int sfd;
static char buf[MAXBUF];
static int len;

int main(void)
{
	s_addr_in.sin_family = AF_INET;
	s_addr_in.sin_port = htons(SERVER_PORT);
	s_addr_in.sin_addr.s_addr = inet_addr(SERVER_IP);
	sfd = socket(AF_INET, SOCK_DGRAM, 0);
	len = read(STDIN, buf, MAXBUF);
	sendto(sfd, buf, len, 0, (SockAddr*)&s_addr_in, sizeof(SockAddrIn));
	len = recvfrom(sfd, buf, MAXBUF, 0, NULL, NULL);
	write(STDOUT, buf, len);
	len = recvfrom(sfd, buf, MAXBUF, 0, NULL, NULL);
	write(STDOUT, buf, len);
	close(sfd);
	return 0; 			
}
